package com.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Author：毕龙
 * Date: 2023/7/21 9:12
 */
public class TestJDBCConnection3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取链接  java访问数据库的一个协议
        // 协议  jdbc:mysql://
        //数据库的ip  localhost:
        //数据库的端口号  3306
        //jdbc:oracle:thin:@localhost:1521/db4
        String url = "jdbc:mysql://localhost:3306/db4";
        //数据库的用户名
        String user = "root";
        //数据用户密码  不一定是root
        String password = "root";
        Connection conn = DriverManager.getConnection(url, user, password);
        System.out.println(conn);
        //3.执行sql
        String sql = "UPDATE USER SET PASSWORD = '000000' WHERE id = 4";
        Statement statement = conn.createStatement();
        statement.execute(sql);

        //4释放资源
        statement.close();
        conn.close();

    }
}
